package com.fengyun.selfbfpp;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;

/**
 * 自定义BFPP实现BeanFactoryPostProcessor和PriorityOrdered接口
 */
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor, PriorityOrdered {

	/**
	 * 执行自定义BFPP的postProcessBeanFactory方法
	 *
	 * @param beanFactory the bean factory used by the application context
	 * @throws BeansException
	 */
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

//		// 获取bd
//		BeanDefinition userBD = beanFactory.getBeanDefinition("user");
//		// 修改bean定义的属性值
//		userBD.getPropertyValues().add("name","laocheng");

		System.out.println("MyBeanFactoryPostProcessor....");
		MyJavaBean myJavaBean = new MyJavaBean();
		myJavaBean.setId(1);
		myJavaBean.setName("xiaohu");
		// 注册一个单例bean
		beanFactory.registerSingleton("myJavaBean",myJavaBean);
		
	}

	/**
	 * 自定义BFPP接口中postProcessBeanFactory()方法执行的顺序
	 *
	 * @return
	 */
	@Override
	public int getOrder() {
		return 0;
	}
}
